package com.sanerzone.smscenter.config.impl;

import com.sanerzone.smscenter.biz.cache.*;
import com.sanerzone.smscenter.biz.entity.SensitiveWords;
import com.sanerzone.smscenter.biz.entity.SmsGateway;
import com.sanerzone.smscenter.biz.entity.SmsGatewayGroup;
import com.sanerzone.smscenter.biz.entity.SmsGatewayGroupRel;
import com.sanerzone.smscenter.biz.iface.CachRefreshInterface;
import com.sanerzone.smscenter.biz.iface.SMSGatewayInterface;

import java.util.Map;

public class SmsGatewayRelInterfaceImpl implements CachRefreshInterface{

    @Override
    public boolean addSmsGatewayRelToCach(SmsGatewayGroupRel smsGatewayGroupRel) {
        return GatewayRelHelper2.refresh( smsGatewayGroupRel );
    }

    @Override
    public boolean updateSmsGatewayCach(SmsGateway smsGateway) {
        GatewayCacheHelper.updateCach( smsGateway );
        return true;
    }
    @Override
    public boolean configSysBlacklist(int type, String phone, String[] phones,String level) {
        switch (type) {
            case 1:
                SysBlacklistHelper.put(phones,level);
                break;
            case 2:
                SysBlacklistHelper.del(phone);
                break;
            case 3:
                SysBlacklistHelper.del(phones);
                break;
            default:
                break;
        }
        return false;
    }
    @Override
    public boolean configSysBlack(Map<String, String> phoneMap) {
        SysBlacklistHelper.putAll( phoneMap );
        return true;
    }

    @Override
    public boolean delGatewayCach(SmsGatewayGroupRel smsGatewayGroupRel) {
      return   GatewayRelHelper2.del( smsGatewayGroupRel );
    }

    @Override
    public boolean updateSensitiveWord(String type, SensitiveWords sensitiveWords) {
        if ("1".equals( type )){
            SensitiveWordsHelper.add( sensitiveWords );
        }else if ("2".equals( type )){
            SensitiveWordsHelper.delete( sensitiveWords );
        }else{
            return false;
        }
        return true;
    }

    @Override
    public boolean updateGatewayGroup(String type, SmsGatewayGroup smsGatewayGroup) {
        try {
            //如果是添加的操作
            if ("1".equals( type )){
                GatewayGroupHelper.put( smsGatewayGroup.getId(),smsGatewayGroup );
                return true;
            }else if("2".equals( type )){
                //如果是删除  先删除这个分组下的网关关系 再删除这个网关组
                GatewayRelHelper2.delAGroup( smsGatewayGroup.getId() );
                GatewayGroupHelper.del( smsGatewayGroup.getId() );
                return true;
            }
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
